Skip to main content

Chapter 7 - Terraform Multiple Providers

Using azurerm and azurerm together

Overview​


You can use multiple providers for multiple regions.

You can use one provider for eastus and one for centralus.

Implement multiple providers​


Use an alias to define multiple providers.

# Terraform Block
terraform {
required_version = ">= 0.15"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 2.0"
}
}
}

# Provider-1 for CentralUS (Default Provider)
provider "azurerm" {
features {}
}

# Provider-2 for EastUS2
provider "azurerm" {
features {
virtual_machine {
delete_os_disk_on_deletion = false # This will ensure when the Virtual Machine is destroyed, Disk is not deleted, default is true and we can alter it at provider level
}
}
alias = "provider2-eastus2"
#client_id = "XXXX"
#client_secret = "YYY"
#environment = "dr"
#subscription_id = "differentsubID"
}